﻿Imports System
Imports System.Collections.Generic
Imports System.Workflow.ComponentModel
Imports System.Workflow.ComponentModel.Design
Imports System.Xml

Namespace System.Workflow.ComponentModel.Serialization
    Public Class CompositeActivityMarkupSerializer
        Inherits ActivityMarkupSerializer
        ' Methods
        Friend Overrides Sub OnBeforeSerializeContents(ByVal serializationManager As WorkflowMarkupSerializationManager, ByVal obj As Object)
            MyBase.OnBeforeSerializeContents(serializationManager, obj)
            Dim activity As CompositeActivity = [TryCast](obj,CompositeActivity)
            Dim writer As XmlWriter = [TryCast](serializationManager.WorkflowMarkupStack.Item(GetType(XmlWriter)),XmlWriter)
            If ((activity.Parent Is Nothing) AndAlso (Not writer Is Nothing)) Then
                Dim dictionary As New Dictionary([Of] String, Activity)
                Dim prefix As String = String.Empty
                Dim xmlQualifiedName As XmlQualifiedName = serializationManager.GetXmlQualifiedName(activity.GetType, prefix)
                dictionary.Add(xmlQualifiedName.Namespace, activity)
                Dim activity2 As Activity
                For Each activity2 In Helpers.GetNestedActivities(activity)
                    prefix = String.Empty
                    xmlQualifiedName = serializationManager.GetXmlQualifiedName(activity2.GetType, prefix)
                    If Not dictionary.ContainsKey(xmlQualifiedName.Namespace) Then
                        writer.WriteAttributeString("xmlns", prefix, Nothing, xmlQualifiedName.Namespace)
                        dictionary.Add(xmlQualifiedName.Namespace, activity2)
                    End If
                Next
            End If
        End Sub

    End Class
End Namespace

